import React from 'react'
// import { useStore } from 'react-redux'
import store from "../redux/store"
import { createIncrementAction, createDecrementAction,
  createAsyncIncrementAction } from '../redux/countAction'

export default function Count() {

  const sum = store.getState()


  const incrementIfOdd = () => {
    if(sum % 2 !== 0) {
      store.dispatch(createIncrementAction(1))
    }
  }
  const incrementAsync = () => {
    
     
      store.dispatch(createAsyncIncrementAction(1))      

 
  }
  return (

    <div>
      <h3>总和: {sum}</h3>
      
      <button onClick={() => store.dispatch(createIncrementAction(1))}>加</button>
      <button onClick={() => store.dispatch(createDecrementAction(1))}>减</button>
      <button onClick={incrementIfOdd}>计数加</button>
      <button onClick={incrementAsync}>异步加</button>
    </div>

  )
}
